package cn.hunau.bookstore.service.impl;

import java.util.Objects;

import cn.hunau.bookstore.dao.AdminDao;
import cn.hunau.bookstore.dao.impl.AdminDaoImpl;
import cn.hunau.bookstore.exception.DaoException;
import cn.hunau.bookstore.pojo.Admin;
import cn.hunau.bookstore.pojo.ResponseResult;
import cn.hunau.bookstore.service.AdminService;

/**
 * @author HuangBo
 *
 *         2022-01-18 15:33:44
 *
 */
public class AdminServiceImpl implements AdminService {
	private AdminDao adminDao = new AdminDaoImpl();
	@Override
	public ResponseResult login(String email, String password) throws DaoException {
		ResponseResult result = null;
		try {
			Admin admin = adminDao.queryByEmailAndPassword(email, password);
			if (Objects.isNull(admin)) {
				result = new ResponseResult(false, "用户名或者密码错误");
			}else {
			 result = new ResponseResult(true, admin);
			}
		} catch (DaoException e) {
			result = new ResponseResult(false, "服务器内部报错");
		}
		return result;
	}

}
